import java.util.Random;

/**
 * 定义方法实现随机产生一个5位的验证码，每位可能是数字、大写字母、小写字母
 */

public class GenerateVerificationCode {
    public static void main(String[] args) {
        String code = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        char[] generateCode = generateCode(code, 8);
        System.out.print("验证码:");
        for (char c : generateCode) {
            System.out.print(c);
        }
    }
    public static char[] generateCode(String code,int number){
        Random random = new Random();
        int length = code.length();
        char[] verificationCodes = new char[number];
        for (int i = 0; i < number; i++) {
            int index = random.nextInt(length);
            verificationCodes[i]= code.charAt(index);
        }
        return verificationCodes;
    }

}
